<template>
  <div class="screen-body" :class="theme">
    <div id="dv-full-screen-container" ref="appRef">
      <dv-loading v-if="loading"></dv-loading>
      <template v-else>
        <div class="header">
          <div class="logo-box">
            <div class="name">
              <h4>{{project && project.projName}}</h4>
            </div>
          </div>
          <div class="nav">
            <div class="menu">
              <div class="item" :class="index == activeMenu ? 'active' : ''" v-for="(item,index) in nav" :key="index" @click="handleChangeNav(index)">
                <span>{{item.name}}</span>
              </div>
            </div>
            <div class="timer">
              <img src="../../assets/images/nav-dot1.png" class="dot1" />
              <div class="time">{{nowtime}}</div>
              <img src="../../assets/images/nav-dot2.png" class="dot2" />
              <div class="date">{{nowdate}}</div>
              <img src="../../assets/images/nav-dot2.png" class="dot3" />
              <div class="week">{{nowweek}}</div>
            </div>
            <img src="../../assets/images/out.png" v-if="userinfo.username !== 'admin'" class="outlogin" @click="outLogin"/>
          </div>
        </div>
        <transition name="fade">
          <component :is="nav[activeMenu].component" :theme="theme" class="screen-bd" :id="projectId" :project="project"></component>
        </transition>
      </template>
    </div>
  </div>
  
</template>

<script>
import moment from 'moment'
import { mapGetters } from 'vuex';
// import drawMixin from "@/utils/drawMixin";
export default{
  // mixins: [drawMixin],
  components:{
    overview:() => import('./components/datap/overview.vue'),
    labour:() => import('./components/datap/labour.vue'),
    aiot:() => import('./components/datap/aiot.vue'),
    environment:() => import('./components/datap/environment.vue'), // 视频监控
    dpvideo:() => import('./components/datap/dpvideo2.vue'), // 视频监控
    quality:() => import('./components/datap/quality.vue'), // 质量安全
    materials:() => import('./components/datap/materials.vue'), // 质量安全
  },
  data(){
    return{
      auths:[
        {name:'视频监控',code:'1-6',component:'dpvideo'},
        {name:'劳务管理',code:'1-2',component:'labour'},
        {name:'环境监测',code:'1-5',component:'environment'},
        {name:'智慧物联',code:'1-3',component:'aiot'},
        //{name:'物资管理',code:'1-4',component:'materials'},
      ],
      nav: [{name:'项目概况',code:'1-1',component:'overview'}],
      activeMenu:0,
      nowDate:new Date(),
      activeComponent:'overview',
      projectId:"",
      project:'',
      loading:true,
      theme:'light'
    }
  },
  computed: {
    ...mapGetters(['userinfo']),
    nowtime(){
      return moment(this.nowDate).format('HH:mm:ss')
    },
    nowweek(){
      let weeks = ['日','一','二','三','四','五','六']
      let e = moment(this.nowDate).format('e')
      return '星期' + weeks[e]
    },
    nowdate(){
      return moment(this.nowDate).format('YYYY/MM/DD')
    },
  },
  created() {
    this.projectId = this.$route.query.id
    console.log(this.projectId)
    this.getProjectInfo()
    // 项目详情
    // this.$api.getDCProjectDetail(this.projectId).then(res => {
    //     console.log(JSON.parse(res.data.bgImage)[2].previewUrl)
    // })
  },
  mounted(){
    setInterval(()=>{
      this.nowDate = new Date()
    },1000)
  },
  methods: {
    handleChangeNav(idx){
      this.activeMenu = idx
    //   this.activeComponent = this.components[idx]
    },
    getProjectInfo(){
      this.$api.getProjectList({projectid:this.projectId}).then(res => {
        if(res.code == 0){
          this.project = res.data[0]
          this.auths.map(item => {
						if(this.project.moduleIds.indexOf(item.code) > -1){
							this.nav.push(item)
						}
					})
        }
        this.loading = false
      })
    },
    outLogin(){
        this.$store.dispatch('user/logout').then((res) => {
        this.$router.push({
            path:"/login"
        })
        }).catch((err)=>{console.log(err)})    
    },
  },
}
</script>

<style lang="scss" scoped>
.screen-body{
  width:100%;
  height: 100%;
  background: #020D1B;
}

#dv-full-screen-container {
  padding: 16px;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-width: 900px;
  overflow-y: auto;
  overflow-x: auto;
  background: url("../../assets/images/p_bg.png") 0 0 no-repeat;
  background-size: cover;
  box-sizing: border-box;
  &.pageisScale {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transform-origin: left top;
  }
  .header{
    width: 100%;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .logo-box{
      width: 566px;
      min-width: 566px;
      height: 50px;
      display: flex;
      align-items: center;
      padding: 0 15px;
      background: url("../../assets/images/title_bg.png") 0 0 no-repeat;
      position: relative;
      margin-right: 30px;
      .logo{
        width: 36px;
        height: 36px;
        margin-right: 15px;
      }
      .name{
        flex: 1;
        display: flex;
        justify-content: center;
        flex-direction: column;
      }
      h2{
        font-family: 'youshe',Microsoft YaHei;
        color: #FFFFFF;
        text-shadow: 0px 0px 9px #159AFF;
        font-size: 20px;
        font-weight: normal;
        margin: 0 0 6px;
        line-height: 1;
      }
      h4{
        font-weight: 400;
        color: #FFFFFF;
        text-shadow: 0px 0px 9px rgba(255,106,58,0.6500);
        font-size: 20px;
        margin: 0;
        line-height: 1;
      }
    }
    .nav{
      background: url("../../assets/images/nav_bg.png") right 0 no-repeat;
      background-size: cover;
      display: flex;
      align-items: center;
      height: 50px;
      .menu{
        display: flex;
        align-items: center;
        .item{
          font-size: 16px;
          color: #D9E7FF;
          width: 128px;
          height: 50px;
          font-weight: 400;
          display: flex;
          align-items: center;
          justify-content: center;
          cursor: pointer;
          position: relative;
          span{
            position: relative;
            z-index: 2;
          }
          &::before{
            content: '';
            width: 96px;
            height: 26px;
            background: rgba(35,44,59,0.6500);
            position: absolute;
            left: 16px;
            top: 12px;
          }
          &::after{
            content: '';
            width: 1px;
            height: 18px;
            background: #D9E7FF;
            opacity: 0.4;
            position: absolute;
            right: 0;
            top: 16px;
          }
          &:last-child::after{
            display: none;
          }
          &.active{
            background: url("../../assets/images/menu_hover.png") 0 0 no-repeat;
            background-size: 100% 100%;
          }
          &:hover{
            text-shadow: 0px 0px 9px #159AFF;
          }
        }
      }
      .timer{
        display: flex;
        align-items: center;
        padding-right: 20px;
        .dot1,.dot2,.dot3{
          margin:0 12px;
        }
        .date,.time,.week{
          font-size: 18px;
          color: #D9E7FF;
        }
      }
    }
  }
  .screen-bd{
    flex: 1;
    padding-top: 30px;
    box-sizing: border-box;
  }
}

.fade-enter-active {
  transition: all .2s ease;
}
.fade-leave-active {
  transition: all .2s cubic-bezier(1.0, 0.5, 0.8, 1.0);
}
.fade-enter, .fade-leave-to {
  opacity: 0;
}


//浅色
.light{
  background: none;
  #dv-full-screen-container{
    background: #F5F7FA;
    .header{
      .logo-box{
        background: url("../../assets/images/title_bg.png") 0 0 no-repeat;
        h2{
          font-family: Microsoft YaHei;
          color: #000;
          text-shadow: none;
        }
        .line{
          background: #0374FE;
        }
        h4{
          color: #000;
          text-shadow: none;
        }
      }
    }
    .nav{
      height: 66px;
      background: url("../../assets/images/nav_bg_light.png") right 0 no-repeat;
      .menu{
        .item{
          color: #333;
          &::before{
            content: '';
            background: #D8D9E3;
          }
          &::after{
            content: '';
            background: #BCBDCB;
          }
          &.active{
            background: url("../../assets/images/menu_hover_light.png") 0 0 no-repeat;
          }
          &:hover,&.active{
            color: #fff;
            &::before{
              content: '';
              background: linear-gradient(90deg, #1D42AB 0%, #1E91FE 100%);
            }
            text-shadow:none
          }
        }
      }
      .timer{
        .date,.time,.week{
          color: #333;
        }
      }
      .outlogin{
        width: 22px;
        height: 23px;
        cursor: pointer;
      }
    }
  }
}

@media(max-width: 1900px){
  .timer{
    .dot3,.week{
      display: none !important;
    }
  }
}
@media(max-width: 1800px){
  .timer{
    .dot3,.week,.date,.dot2{
      display: none !important;
    }
  }
}
@media(max-width: 1642px){
  .timer{
    display: none !important;
  }
}

@media (max-height:860px) {
  #dv-full-screen-container .screen-bd{
    padding-top: 20px !important;
  }
}
@media (max-width:1200px) {
  .logo-box{
    width: 266px !important;
    min-width: 266px !important;
  }
}

</style>